<template>
  <a-modal v-model:open="isOpen" title="分享图片" :footer="false" @cancel="closeModal">
    <h4>复制分享链接</h4>
    <a-typography-link copyable>
      {{ link }}
    </a-typography-link>
    <div style="margin-bottom: 16px" />
    <h4>手机扫码查看</h4>
    <a-qrcode class="qrcode" :value="link" />
  </a-modal>
</template>

<script setup lang="ts">
import { defineExpose, defineProps, ref, withDefaults } from 'vue'

/**
 * 定义组件属性类型
 */
interface Props {
  title: string
  link: string
}

/**
 * 给组件指定初始值
 */
const props = withDefaults(defineProps<Props>(), {
  title: () => '分享',
  link: () => 'https://xxxx/share/',
})

const isOpen = ref(false)

// 打开弹窗
const showModal = () => {
  isOpen.value = true
}

// 关闭弹窗
const closeModal = () => {
  isOpen.value = false
}

// 暴露函数给父组件
defineExpose({
  showModal,
})
</script>
<style scoped>
/* 调整模态框内边距 */
.a-modal-body {
  padding: 24px !important;
}

/* 标题样式 */
h4 {
  color: rgba(0, 0, 0, 0.85);
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 12px;
  position: relative;
  padding-left: 8px;
}

h4::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 3px;
  background-color: #1890ff;
  border-radius: 2px;
}

/* 链接区域美化 */
:deep(.ant-typography) {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background-color: #f5f5f5;
  border-radius: 4px;
  transition: all 0.3s;
}

:deep(.ant-typography-copy) {
  color: #1890ff !important;
  opacity: 0.8;
}

:deep(.ant-typography-copy:hover) {
  opacity: 1;
  transform: scale(1.1);
}

/* 二维码容器美化 */
.qrcode :deep {
  margin: 12px auto 0; /* 上边距12px 水平自动居中 */
  padding: 16px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: block;
}

/* 调整模态框标题样式 */
:deep(.ant-modal-title) {
  font-size: 18px !important;
  color: rgba(0, 0, 0, 0.85) !important;
  font-weight: 600 !important;
}

/* 关闭按钮颜色 */
:deep(.ant-modal-close-x) {
  color: rgba(239, 33, 33, 0.45);
}

/* 间距优化 */
div[style='margin-bottom: 16px'] {
  margin-bottom: 24px !important;
  border-bottom: 1px solid #f0f0f0;
  padding-bottom: 24px;
}
</style>
